home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11491 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: solon.com!not-for-mail
  2. From: Michael Smith <msmith@mpx.com.au>
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated,hp.unix,comp.sys.hp.apps,comp.sys.hp.hpux
  4. Subject: Re: C coding problem
  5. Date: 24 Mar 1996 11:47:42 -0600
  6. Organization: Emmenjay Consulting
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4j41ru$nq4@solutions.solon.com>
  10. References: <4ianbf$h86@solutions.solon.com> <4iemcl$a05@solutions.solon.com> <4io1io$no4@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Mailer: Mozilla 2.0 (Win16; I)
  13.  
  14. Konrad Schwarz wrote:
  15. > I recently wrote a loop that went like this:
  16. > while (p < end_p)
  17. >         ++*p++;
  18.  
  19. This is largely a matter of taste, but personally I don't like that 
  20. construct.  A programmer less skilled than you might easily misunderstand 
  21. that and introduce an error.  I would prefer:
  22.  
  23. for ( ; p<end_p; p++) 
  24.     ++(*p);
  25.  
  26. This is likely to run just as fast (particularly with an optimizing 
  27. compiler) but there is much less chance of a future maintenance 
  28. programmer misunderstanding it.  The brackets around "*p" are, of course, 
  29. redundant, but (in my opinion) add to the clarity.
  30.  
  31. -- 
  32. #####################################################################
  33. Michael Smith                                       msmith@mpx.com.au
  34. Emmenjay Consulting                 http://www.hutch.com.au/~emmenjay
  35. #####################################################################
  36.